﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using WCrawlerLib;

namespace WCrawler.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
#if DEBUG
                WCrawlerLib.AppSettings.my_mpconfigConnectionString = ConfigurationManager.ConnectionStrings["my_mpconfigConnectionString"].ToString();
#else
                WCrawlerLib.AppSettings.my_mpconfigConnectionString = ConfigurationManager.ConnectionStrings["my_mpconfigConnectionString"].ToString();
#endif
            }

            RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        }

        protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
        {
            string username = this.LoginUser.UserName;
            string password = this.LoginUser.Password;
            WCrawlerLib.User objUser = new WCrawlerLib.User();

            if (objUser.CheckLogin(username, password))
            {
                FormsAuthentication.RedirectFromLoginPage(username, LoginUser.RememberMeSet);
                //Session["login"] = username;
                //if (LoginUser.RememberMeSet)
                //{
                //    Response.Cookies["user"].Value = username + "__" + DateTime.Now.Year.ToString();
                //    Response.Cookies["user"].Expires = DateTime.Now.AddDays(7);
                //}
                //Response.Redirect("../Default.aspx");
            }
        }
    }
}
